<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
</head>

<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left" tapmode onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">债权转让</div>
    </header>
    <div class="aui-bar-nav-d"></div>


    <style>
        body {
            background: #fff;
        }
    </style>
    <dl class="claims-details-1">
        <dt id="name"></dt>
        <dd id="qishu">待还/总期数：<span id="nextDay">下个还款日：</span></dd>
    </dl>

    <div class="claims-details-3 diy-brd5">
        <img src="image/claims-details-3.jpg" alt=""> 转让价格（元）
        <span id="zhuanrang"></span>
    </div>


    <ul class="claims-details-4" style="margin:0">
        <li id="mount"></li>
        <li id="lixi">剩余利息：￥</li>
        <li>转让折扣：
            <select id="select1">
            <option value ="1">无折扣</option>
            <option value ="0.99">9.9折</option>
            <option value ="0.95">9.5折</option>
            <option value ="0.9">9.0折</option>
            <option value ="0.85">8.5折</option>
            <option value ="0.8">8.0折</option>
            <option value ="0.75">7.5折</option>
            <option value ="0.7">7.0折</option>
            <option value ="0.65">6.5折</option>
            <option value ="0.6">6.0折</option>
            <option value ="0.55">5.5折</option>
            <option value ="0.5">5.0折</option>
        </select>
        </li>
    </ul>
    <div class="user-claims-details-d">
        <p>温馨提示：</p>
        <p>1、债权转让金额不得大于所投剩余本金。</p>
        <p>2、债权转让的费用为转让管理费。平台向转出人收取，不向购买人收取任何费用。转让管理费金额为剩余本金*0.5%。</p>
    </div>

    <div class="claims-details-btn" onclick="zhuanrang()">确认转让</div>

</body>
<script type="text/javascript">
    var deal_sn = '';
    var userid = '';
    var name = '';
    var mount = '';
    var deal_id = '';
    apiready = function() {
        deal_sn = api.pageParam.deal_sn;
        name = api.pageParam.name;
        mount = api.pageParam.mount;
        deal_id = api.pageParam.deal_id;

        userid = $api.getStorage('userid');
        load_list();
        changeMoney();


    }

    function load_list() {
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        api.ajax({
            url: webAddress + '/index.php?ctl=deal&act=to_transfer',
            method: 'post',
            data: {
                values: {
                    deal_sn: deal_sn,
                    user_id: userid
                },
            }
        }, function(ret, err) {
            if (ret) {
                // alert( JSON.stringify( ret ) );
                // updateList(ret);
                $("#name").text(name);

                $("#mount").text("剩余本金：￥" + mount);

                // $("#qishu").text("待还/总期数："+ret.residuePeriods+"/12");
                $("#qishu").html("待还/总期数：" + ret.residuePeriods + "/12<span>下个还款日：" + ret.nextRepayTime + "</span>");
                $("#lixi").text("剩余利息：￥" + ret.residueInterest);
                // $("#nextDay").text("下个还款日："+ret.nextRepayTime);
                $("#zhuanrang").text("￥" + mount);
                api.hideProgress();
            } else {
                alert(JSON.stringify(err));
            }
        });

    }

    function changeMoney() {
        $("#select1").change(function() {
            var zhekou = $("#select1  option:selected").val();
            var change = mount * zhekou;
            $("#zhuanrang").text("￥" + change);
        });

    }

    // function updateList(data) {
    //     var template = $api.byId('template');
    //     var dotFn = doT.template(template.innerHTML);
    //     var html = dotFn(data);
    //     var list = $api.byId('list');
    //     $api.html(list, html);
    //
    // }

    function zhuanrang() {

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });

        var z = Number($("#select1  option:selected").val());
        // alert(userid);
        // alert(deal_id);
        // alert(z);
        // return;

        var uid = Number(userid);
        var did = Number(deal_id);

        api.ajax({
            url: 'http://big-wealth.com/index.php?ctl=deal&act=do_transfer',
            method: 'post',
            data: {
                values: {
                    user_id: uid,
                    deal_id: did,
                    transferDiscount: z,
                },
            }
        }, function(ret, err) {
            if (ret) {
                // alert(11);
                // alert(JSON.stringify(ret));
            } else {
                // alert(22);
                // alert(JSON.stringify(err.body));
                if (err.body == '1') {
                    // alert(33);
                    alert('转让成功！');
                    api.execScript({
                        name: 'user_claims_list',
                        script: 'load_list()'
                    });
                    api.hideProgress();

                    closeWin();
                } else {
                    alert("请求错误");
                }
            }
        });



    }

    function closeWin() {
        api.closeWin({});
    }
    $(".claims-details-2-d").on('click', function() {
        $(".claims-details-2 ul").toggleClass("claims-details-2-h");
    })
</script>

</html>
